package tag35_28_08.map;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;

public class Map01_UseMap {

	public static void main(String[] args) {
		Map<Integer, String> map = new HashMap<Integer, String>();

		System.out.println("size: " + map.size());

		map.put(1, "Mo");
		System.out.println("size: " + map.size());
		System.out.println(map);

		map.put(2, "Di");
		map.put(3, "Mi");
		System.out.println(map); // {1=Mo, 2=Di, 3=Mi}

		String oldValue = map.put(4, "Do");
		System.out.println(oldValue);

		oldValue = map.put(4, "Donnerstag");
		System.out.println(oldValue);

		System.out.println("-------------------------");
		String value = map.get(5);
		System.out.println("value for 5: " + value);
		System.out.println("value for 4: " + map.get(4));

		Map<? extends Number, String> mapLocker = map;
		mapLocker.get(4);

		System.out.println("--------------------------------------");
		Set<Integer> setKeys = map.keySet();

		for (Integer key : setKeys) {
			String val = map.get(key);
			System.out.println(key + " = " + val);
		}

		System.out.println("--------------------------------------");
		Collection<String> values = map.values();
		System.out.println(values);

		System.out.println("---------------------------------------");
		Set<Map.Entry<Integer, String>> allEntries = map.entrySet();

		for (Map.Entry<Integer, String> var : allEntries) {
			System.out.println(var);
			System.out.println(" --> " + var.getKey() + " = " + var.getValue());
		}

		System.out.println("-------------------------------------------");
		class Auto {
			int baujahr;
		}

		Map<Integer, Auto> mapAutos = new TreeMap<Integer, Auto>();
		mapAutos.put(3000, new Auto());
		mapAutos.put(-2, new Auto());
		mapAutos.put(77, new Auto());

		System.out.println(mapAutos);

		for (Map.Entry<Integer, Auto> entry : mapAutos.entrySet()) {
			Integer k = entry.getKey();
			Auto a = entry.getValue();
			System.out.println(k + " = " + a);
		}

	} // end of man

}
